package noppes.vc;

import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.util.NonNullList;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.registries.IForgeRegistryEntry.Impl;

class VCRecipes$RecipeReverse extends Impl<IRecipe> implements IRecipe {
   private final Item[] items;
   // $FF: synthetic field
   final VCRecipes this$0;

   public VCRecipes$RecipeReverse(VCRecipes this$0) {
      this.this$0 = this$0;
      this.items = new Item[]{VCWeapons.wooden_dagger, VCWeapons.wooden_dagger_reversed, VCWeapons.stone_dagger, VCWeapons.stone_dagger_reversed, VCWeapons.iron_dagger, VCWeapons.iron_dagger_reversed, VCWeapons.golden_dagger, VCWeapons.golden_dagger_reversed, VCWeapons.diamond_dagger, VCWeapons.diamond_dagger_reversed, VCWeapons.bronze_dagger, VCWeapons.bronze_dagger_reversed, VCWeapons.emerald_dagger, VCWeapons.emerald_dagger_reversed, VCWeapons.demonic_dagger, VCWeapons.demonic_dagger_reversed, VCWeapons.frost_dagger, VCWeapons.frost_dagger_reversed, VCWeapons.mithril_dagger, VCWeapons.mithril_dagger_reversed};
      VCRecipes$RecipeContainer c = new VCRecipes$RecipeContainer(this$0);

      for(int i = 0; i < this.items.length; i += 2) {
         c.add(new ItemStack(this.items[i]), new ItemStack(this.items[i + 1]));
         c.add(new ItemStack(this.items[i + 1]), new ItemStack(this.items[i]));
      }

   }

   public boolean matches(InventoryCrafting inv, World worldIn) {
      return !this.getCraftingResult(inv).isEmpty();
   }

   public ItemStack getCraftingResult(InventoryCrafting inv) {
      for(int i = 0; i < inv.getSizeInventory(); ++i) {
         ItemStack itemstack = inv.getStackInSlot(i);

         for(int j = 0; j < this.items.length; ++j) {
            if (this.items[j] == itemstack.getItem()) {
               return CommonUtils.ChangeItemStack(itemstack, this.items[j + (j % 2 == 1 ? -1 : 1)]);
            }
         }
      }

      return ItemStack.EMPTY;
   }

   public ItemStack getRecipeOutput() {
      return ItemStack.EMPTY;
   }

   public NonNullList<ItemStack> getRemainingItems(InventoryCrafting inv) {
      NonNullList<ItemStack> nonnulllist = NonNullList.withSize(inv.getSizeInventory(), ItemStack.EMPTY);

      for(int i = 0; i < nonnulllist.size(); ++i) {
         ItemStack itemstack = inv.getStackInSlot(i);
         nonnulllist.set(i, ForgeHooks.getContainerItem(itemstack));
      }

      return nonnulllist;
   }

   public boolean canFit(int width, int height) {
      return width == 1 && height == 1;
   }
}
